import os
import logging
import pathlib
import src.utils.stream as stream


logger = logging.getLogger(__file__)


class Config(dict):
    _default = {
        "models_dir": "models",
        "datasets_dir": "dataset"
    }

    @classmethod
    def from_file(cls, path: str | pathlib.Path):
        try:
            config = stream.read_yaml(path)
            for key_default in cls._default:
                if key_default not in config:
                    raise ValueError(f"Not key: {key_default} in {path}")
        except Exception as error:
            logger.error(error)
        else:
            return cls(config)
